package com.javafactroy.kunlong.test.engine;

import cn.hutool.core.lang.Console;
import com.javafactroy.kunlong.DbAgent;
import com.javafactroy.kunlong.base.model.ReturnPageInfo;
import com.javafactroy.kunlong.client.feign.dto.ApiResult;
import com.javafactroy.kunlong.data.dto.TSysUserApiDto;
import com.javafactroy.kunlong.data.service.TSysUserApiService;
import com.javafactroy.kunlong.common.utils.CommonUtils;
import com.javafactroy.kunlong.framework.generalthread.GeneralThread;
import com.javafactroy.kunlong.framework.generalthread.TGeneralDataRunner;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.concurrent.ExecutionException;

/**
 * @author raymond.lei@163.com
 * @date 2023-10-29 12:29:16
 */

@SpringBootTest(classes = {DbAgent.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ExtendWith(SpringExtension.class)
@Slf4j
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestThread {

    @Autowired
    GeneralThread<TSysUserApiDto> generalThread;

    @Autowired
    TSysUserApiService sysUserApiService;

    @Test
    public void test001_thread() throws InterruptedException, ExecutionException {
        TSysUserApiDto sysUserApiDto = new TSysUserApiDto();
        sysUserApiDto.setPageSize(11);

        ReturnPageInfo inf = sysUserApiService.query(sysUserApiDto);
        TGeneralDataRunner<TSysUserApiDto> dataRunner = new TGeneralDataRunner();
        dataRunner.setThreadWaitMinutes(5).setThreadNum(4).setList(inf.getList());

        ApiResult<TSysUserApiDto> result = generalThread.exec(dataRunner);

        Console.log(result.toString());
    }

    @Test
    public void test002_query() throws InterruptedException {
        TSysUserApiDto sysUserApiDto = new TSysUserApiDto();
        sysUserApiDto.setPageSize(12);

        sysUserApiDto.setId(1);
        ReturnPageInfo inf = sysUserApiService.query(sysUserApiDto);
        log.info("inf={}", CommonUtils.toJSONString(inf));

    }

    @Test
    public void test003_webClient() throws InterruptedException {
//        WebClient webClient = WebClient.create();
//
//        Mono<String> mono = webClient.get().uri("https://www.baidu.com").retrieve().bodyToMono(String.class);
//        System.out.println(mono.block());
    }

}

